package product

import (
	"github.com/gin-gonic/gin"
	"mallgo/internal/common/response"
	modelRequest "mallgo/internal/resources/product/api/domain/request"
	"mallgo/internal/resources/product/resource"
)

type ProductCatalogController struct {
	productCatalogResource *resource.ProductCatalogResource
}

func NewProductCatalogController(productCatalogResource *resource.ProductCatalogResource) *ProductCatalogController {
	return &ProductCatalogController{productCatalogResource: productCatalogResource}
}

func (c *ProductCatalogController) Create(ctx *gin.Context) {
	var request modelRequest.ProductCatalogRequest
	if err := ctx.ShouldBindJSON(&request); err != nil {
		ctx.JSON(200, response.Error(501, "请求参数错误"))
		return
	}
	r := c.productCatalogResource.Create(&request)
	r.ToJSON(ctx)
}
